package com.mazaiting.auth;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;

/**
 * 认证服务启动类
 * 0. 新增授权模式后, 刷新令牌需要修改 refresh 服务 - PreAuthenticatedUserDetailsService
 * 1. 解决Caused by: java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass(java.lang.String,[B,int,int,java.lang.ClassLoader,java.security.ProtectionDomain)
 *  启动时需要添加 VM 参数: --add-opens java.base/java.lang=ALL-UNNAMED
 * 2. 解决Caused by: com.google.gson.JsonIOException: Failed making field 'java.io.File#path' accessible; either change its visibility or write a custom TypeAdapter for its declaring type
 *  启动时需要添加 VM 参数: --add-opens java.base/java.io=ALL-UNNAMED
 * 3. 解决Caused by: com.google.gson.JsonIOException: Failed making field 'java.util.concurrent.locks.ReentrantLock#sync' accessible; either change its visibility or write a custom TypeAdapter for its declaring type
 *  启动时需要添加 VM 参数: --add-opens java.base/java.util.concurrent.locks=ALL-UNNAMED
 * - 启动参数
 *   --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED
     --add-opens java.base/java.util.concurrent.locks=ALL-UNNAMED
 * @author mazaiting
 * @create_time 2022/4/2 12:59
 */
@RefreshScope
@EnableCaching
@ServletComponentScan(basePackages = "com.mazaiting")
// 激活远程调用
@EnableFeignClients(basePackages = "com.mazaiting")
@ComponentScan(basePackages = "com.mazaiting")
@EnableDiscoveryClient
@SpringBootApplication
public class ApolloAuthApplication {

    public static void main(String[] args) {
        try {
            SpringApplication.run(ApolloAuthApplication.class, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
